package com.exam.sacrifice.ui.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.exam.commonbiz.net.HostUrl;
import com.exam.sacrifice.R;
import com.exam.sacrifice.ui.bean.ActivityInfo;
import com.exam.sacrifice.util.GlideUtil;
import com.makeramen.roundedimageview.RoundedImageView;

public class ActivityAdapter extends BaseQuickAdapter<ActivityInfo, BaseViewHolder> {

    private OnItemClickListener listener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        listener = onItemClickListener;
    }

    public ActivityAdapter() {
        super(R.layout.item_layout_activity, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, ActivityInfo item) {

        helper.setText(R.id.tv_name, item.activityName);
        helper.setText(R.id.tv_addr, item.activityAddr);
        helper.setText(R.id.tv_time, item.activityStartDate + " - " + item.activityEndDate);
        helper.setText(R.id.tv_num, String.format("已报名%s人", item.applyNum));

        helper.setText(R.id.tv_status, "未开始");

        RoundedImageView roundedImageView = helper.getView(R.id.iv_bg);
        GlideUtil.loadImage(helper.itemView.getContext(), HostUrl.PIC_URL + item.activityDetailUrl, roundedImageView);

        helper.itemView.setOnClickListener(v -> {
            if (listener != null) {
                listener.onItemClick(item);
            }
        });
    }

    public interface OnItemClickListener {
        void onItemClick(ActivityInfo item);
    }
}
